/*
 * FormNuevoCd.java
 *
 * Created on 20 de diciembre de 2005, 0:41
 */

package fmap.gui;

import fmap.DatosCompartidos;
import fmap.dao.CatDao;
import fmap.utils.FormUtils;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;

/**
 *
 * @author  javi
 */
public class JFrameNewMapF extends javax.swing.JFrame
{
    javax.swing.JFileChooser fDialog = new javax.swing.JFileChooser();
    Vector vCategorias = new Vector();
    String icon = "/fmap/img/mapF/2.png";


    /** Creates new form FormNuevoCd */
    public JFrameNewMapF()
    {
        initComponents();

        Vector vCats = new CatDao().selectCats ();
        if( vCats.size () > 0 )
        {
            comboBoxCatMapF.setModel( new DefaultComboBoxModel( vCats ) );
        }
                    
        fmap.gui.actionListener.ListenerJFrameNewMapF listener = 
                new fmap.gui.actionListener.ListenerJFrameNewMapF(
                                                            fDialog,
                                                            txtRuta,
                                                            txtTitCd,
                                                            comboBoxCatMapF,
                                                            textPaneDesc
                                                      );

        fDialog.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);

        boton1.addActionListener( listener );
        boton2.addActionListener( listener );
        boton3.addActionListener( listener );
        buttonIcon.addActionListener ( listener );
        buttonAdminCatMapF.addActionListener ( listener );

        FormUtils.centra(this);
        this.addWindowListener ( new ListenerWindow() );

        setVisible( true );
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        jProgress = new javax.swing.JProgressBar();
        boton2 = new javax.swing.JButton();
        boton1 = new javax.swing.JButton();
        lblEstadoAlta = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        textLogNewMapF = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        txtTitCd = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        buttonIcon = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        comboBoxCatMapF = new javax.swing.JComboBox();
        buttonAdminCatMapF = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtRuta = new javax.swing.JTextField();
        boton3 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        textPaneDesc = new javax.swing.JTextPane();
        jSeparator1 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Fmap - Nuevo volumen de ficheros");
        setAlwaysOnTop(true);

        boton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fmap/img/save.png")));
        boton2.setText("Guardar");
        boton2.setActionCommand("guardar");
        boton2.setMargin(new java.awt.Insets(0, 14, 0, 14));
        boton2.setName("");
        boton2.setPreferredSize(new java.awt.Dimension(83, 21));

        boton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fmap/img/cancel.png")));
        boton1.setText("Cancelar");
        boton1.setActionCommand("cancelar");
        boton1.setAlignmentY(0.0F);
        boton1.setName("");
        boton1.setPreferredSize(new java.awt.Dimension(87, 21));

        lblEstadoAlta.setFont(new java.awt.Font("Dialog", 0, 12));

        jLabel4.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel4.setText("Introduzca los datos de su nuevo volumen de ficheros");

        textLogNewMapF.setColumns(20);
        textLogNewMapF.setEditable(false);
        textLogNewMapF.setRows(5);
        jScrollPane1.setViewportView(textLogNewMapF);

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel1.setText("Nombre");

        txtTitCd.setToolTipText("Introduzca aqui el nombre del recurso que esta dando de alta");

        jLabel6.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel6.setText("Imagen");

        buttonIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fmap/img/mapF/2.png")));
        buttonIcon.setActionCommand("openImagen");
        buttonIcon.setName("openImagen");

        jLabel5.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel5.setText("Categoria");

        comboBoxCatMapF.setFont(new java.awt.Font("Dialog", 0, 12));
        comboBoxCatMapF.setOpaque(false);
        comboBoxCatMapF.setPreferredSize(new java.awt.Dimension(32, 22));

        buttonAdminCatMapF.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fmap/img/cat_edit.png")));
        buttonAdminCatMapF.setToolTipText("Editar categorias");
        buttonAdminCatMapF.setActionCommand("adminCatMapF");
        buttonAdminCatMapF.setName("adminCatMapF");
        buttonAdminCatMapF.setPreferredSize(new java.awt.Dimension(50, 22));

        jLabel2.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel2.setText("Ruta Origen");

        txtRuta.setToolTipText("Introduzca aqui el origen del recurso");

        boton3.setText("Examinar");
        boton3.setActionCommand("examinar");
        boton3.setName("");

        jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel3.setText("Descripcion");

        jScrollPane2.setViewportView(textPaneDesc);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(1, 1, 1)
                        .add(jLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(219, 219, 219)
                        .add(boton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 18, Short.MAX_VALUE)
                        .add(boton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 113, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel5)
                            .add(jLabel1)
                            .add(jLabel2))
                        .add(12, 12, 12)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, txtTitCd, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                            .add(txtRuta, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                            .add(comboBoxCatMapF, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(boton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(buttonAdminCatMapF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(layout.createSequentialGroup()
                                .add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 45, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(buttonIcon, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(lblEstadoAlta, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(jProgress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(15, 15, 15)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtTitCd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(buttonIcon, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(buttonAdminCatMapF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(comboBoxCatMapF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(12, 12, 12)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtRuta, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(boton3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(7, 7, 7)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(boton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(boton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(15, 15, 15)
                .add(lblEstadoAlta, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jProgress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton boton1;
    private javax.swing.JButton boton2;
    private javax.swing.JButton boton3;
    private javax.swing.JButton buttonAdminCatMapF;
    private javax.swing.JButton buttonIcon;
    private javax.swing.JComboBox comboBoxCatMapF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JProgressBar jProgress;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblEstadoAlta;
    private javax.swing.JTextArea textLogNewMapF;
    private javax.swing.JTextPane textPaneDesc;
    private javax.swing.JTextField txtRuta;
    private javax.swing.JTextField txtTitCd;
    // End of variables declaration//GEN-END:variables

    
    public JComboBox getComboBoxCatMapF()
    { return comboBoxCatMapF; }
    public javax.swing.JLabel getLblEstadoAlta()
    { return lblEstadoAlta; }
    public javax.swing.JProgressBar getProgress()
    { return jProgress; }
    public javax.swing.JButton getJButtonCancelar()
    { return boton1; }
    public javax.swing.JButton getJButtonGuardar()
    { return boton2; }
    
    public void setIcon( String _icon)
    {
        icon = _icon;
        buttonIcon.setIcon ( new ImageIcon ( getClass ().getResource (icon) ) );
    }
    
    public String getIcon()
    {
        return icon;
    }

    public void desActiveComponents ()
    {
        boton1.setEnabled ( false );
        boton2.setEnabled ( false );
        boton3.setEnabled ( false );
        txtRuta.setEnabled ( false );
        txtTitCd.setEnabled ( false );
        comboBoxCatMapF.setEnabled ( false );
    }

    public void setTextLogNewMapF ( String _text, boolean sobreescribir)
    {
        if( sobreescribir == true ) 
            textLogNewMapF.setText ( _text );
        else
        {
            if( textLogNewMapF.getText ().trim ().equals ("") )
                textLogNewMapF.setText ( _text );
            else
                textLogNewMapF.setText ( textLogNewMapF.getText () + "\n" + _text );
        }
    }


    public class ListenerWindow implements WindowListener
    {
        // Constructor que guarda la referencia al objeto JFrame
        public ListenerWindow ()
        {}
        
        public void windowClosed ( WindowEvent evt )
        {
            // Cuando cerramos la ventana => activamos el jFrameMain
            DatosCompartidos.getJFrameMain ().activeComponents ();
            
            DatosCompartidos.getJFrameMain ().getGlass ().setNeedToRedispatch (true);
            DatosCompartidos.getJFrameMain ().getGlass ().setVisible (false);
        }
        
        public void windowIconified ( WindowEvent evt )
        {}
        public void windowOpened ( WindowEvent evt )
        {
            // Cuando abrimos la ventana => desactivamos el jFrameMain
            DatosCompartidos.getJFrameMain ().desActiveComponents ();
            DatosCompartidos.getJFrameMain ().setLblMsj ("");
            
            DatosCompartidos.getJFrameMain ().getGlass ().setNeedToRedispatch (false);
            DatosCompartidos.getJFrameMain ().getGlass ().setVisible (true);
        }
        public void windowClosing ( WindowEvent evt )
        {}
        public void windowDeiconified ( WindowEvent evt )
        {}
        public void windowActivated ( WindowEvent evt )
        {}
        public void windowDeactivated ( WindowEvent evt )
        {}
        
    }
}